package com.lws.basic.utils.file;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class StreamUtils {
    /**
     * 输入流转输出流，即拷贝
     * @param in  高效输入流
     * @param out 高效输出流
     * @throws IOException  输入输出异常
     */
    public static void inputOutput(BufferedInputStream in, BufferedOutputStream out) throws IOException {
        try {
            int b;
            while((b = in.read()) != -1) {
                out.write(b);
            }
            in.close();
            out.close();
        } finally {
            in.close();
            out.close();
        }
    }

    /**
     * @param file 文件
     * @return 输出流
     */
    public static FileOutputStream generateOutputStream(File file) {
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(file);
            return fileOutputStream;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return fileOutputStream;
    }


}
